﻿
     using DigDes.DSchool.SUPS.DataAccess.Interface;
 	 using System.IO;
	 using System;
	 using System.Collections.Generic;
	 using System.Linq;
	 using System.Text;
	 using System.Threading.Tasks;
	  
	 namespace DigDes.DSchool.SUPS.DataAccess.FileLoaders
	 {
	     public class MyLoader1 : ILoader<MyLoader1DTO>
	     {
	         // TODO: Реализовать интерфейс загрузчика и логику проверки типа файла/лоигку загрузки файла
	  
	         public bool Check(string filePath)
	         {
	             System.IO.FileInfo file = new System.IO.FileInfo(filePath);
	             if (file.Extension == ".OUT")
	                 return true;
	             else
	                 return false;
	         }
	  
         public IEnumerable<MyLoader1DTO> Load(string filePath)
	         {
	  
	             using (StreamReader sr = new StreamReader(filePath))
	             {
	                 string line;
	                
                 while ((line = sr.ReadLine()) != null)
	                 {
	                     var row = new MyLoader1DTO();
	                     row.InventoryCarriageNumber = line.Substring(0, 8);
	                     row.WeightTons = line.Substring(8, 3);
                         row.DestinationStation = line.Substring(11, 5);
	                     row.CargoCodeTariff = line.Substring(16, 5);
	                     row.СonsigneeCode = line.Substring(21, 4);
	                     row.ParkType = line.Substring(25, 2);
	                     row.StartStation = line.Substring(27, 5);
	                     row.OperationCode = line.Substring(32, 2);
	                     row.OperationDate = line.Substring(34, 4);
	                     row.OperationYear = line.Substring(38, 2);
	                     row.OperationTime = line.Substring(40, 4);
	                     row.StationOfOperation = line.Substring(44, 5);
	                     row.DeliveryRoad = line.Substring(49, 2);
	                     row.ReceptionRoad = line.Substring(51, 2);
	                     row.TrainIndex = line.Substring(53, 13);
	                     row.TrainNumber = line.Substring(66, 4);
	                     yield return row;
	                 }
	             }
	         }
	     }
	 }